package fx.mine.active.util;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPath;
import fx.mine.active.component.music.PlayItemsContent;
import io.github.palexdev.materialfx.controls.MFXButton;
import javafx.scene.image.ImageView;

import java.util.function.Supplier;

public abstract class ParseUtil {

    public static <T> T parse(Supplier<T> supplier) {
        return supplier.get();
    }

    private static PlayItemsContent.PlayItem getPlayItem(Object o) {
        JSONObject object = (JSONObject) o;
        var playItem = new PlayItemsContent.PlayItem();
        playItem.setId(object.getLong("id"));
        playItem.setName((String) JSONPath.eval(o, "$.name"));
        playItem.setPlayer((String) JSONPath.eval(o, "$.ar[0].name"));
        String url = (String) JSONPath.eval(o, "$.al[0].picUrl");
        if (StrUtil.isNotBlank(url)) {
            ImageView imageView = new ImageView(url);
            imageView.setFitWidth(200);
            imageView.setFitHeight(200);
            MFXButton mfxButton = new MFXButton("", imageView);
            mfxButton.setPrefSize(250, 210);
            playItem.setIconUrl(mfxButton);
        }
        return playItem;
    }
}
